1. Field of the Invention
The invention is in the field of computer graphics, and more particularly to calculating depth values in a graphics pipeline.
2. Description of the Related Art
Recent advances in graphics processors permit users to program graphics pipeline units using fragment or pixel programs to implement a variety of user defined shading algorithms. Traditionally, a graphics processor calculated an interpolated depth value for each pixel dependent on x and y coordinates of a geometry primitive, e.g., triangle or polygon that the interpolated depth value was associated with. The interpolated depth value was passed through the graphics pipeline, pixels were clipped by discarding the pixels whose interpolated depth value was outside of the space between the near and far clipping planes, and the retained pixel depth values were used during the depth test.
A desire for greater flexibility in computations has resulted in modifications in the traditional graphics processor to permit the calculation not only of the traditional interpolated depth values, but also to perform further calculations based on the interpolated depth values to generate modified depth values. As illustrated in FIG. 1, a Graphics Subsystem 120 calculates traditional interpolated depth values in a Rasterizer 150. The interpolated depth values are pipelined through a Texturer 155 to a Pixel Unit 160. The interpolated depth values are used to compute modified depth values in Pixel Unit 160. The modified depth values are received by a Raster Operation Unit 165 that clips the pixels associated with the depth values and performs the depth test operation.
At least one application programming interface (API), OpenGL® API 1.3, prefers that clipping be performed using interpolated depth values rather than modified depth values, even when modified depth values are generated. However, when Pixel Unit 160 outputs modified depth values it is not possible for a unit downstream in the pipeline, such as the Raster Operation Unit 165, to clip pixels using the interpolated depth values. It is also not possible to recalculate the interpolated depth values because the inputs needed for the interpolation calculation are not available to Raster Operation Unit 165. However, some pixel programs do clip pixels using the modified depth values. Therefore it is still desirable to compute modified depth values and then clip using either modified depth values or interpolated depth values.
Further, the interpolated depth values and the modified depth values are both typically computed dependent on the coordinates of the geometry primitive. However, there is a desire to implement pixel programs that compute depth values that are independent of the coordinates of the geometry primitive, such as depth values read from memory using map indices u and v.
For the foregoing reasons, there is a need for a graphics system that can generate not only interpolated depth values and modified depth values, but also arbitrary depth values that are independent of the coordinates of a geometry primitive. Furthermore, there is a need for a graphics system that can clip pixels using either calculated depth values or interpolated depth values, where calculated depth values are either modified depth values or arbitrary values, and select between interpolated depth values and calculated depth values to determine the final depth values for depth testing.